package com.yuanfeng.activity.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.activity.entity.ActivityReductionPolicyBaseEntity;
import com.yuanfeng.activity.mapper.ActivityReductionPolicyBaseMapper;
import com.yuanfeng.activity.service.ActivityReductionPolicyBaseService;
import com.yuanfeng.commoms.dto.goods.ListPageQueryParamDTO;
import com.yuanfeng.commoms.dto.goods.ManjianzengzheGoodsRuleQueryDTO;
import com.yuanfeng.commoms.exception.BizCodeEnume;
import com.yuanfeng.commoms.util.ParseMapUtils;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.commoms.util.querypage.PageUtils;
import com.yuanfeng.commoms.util.querypage.Query;
import com.yuanfeng.commoms.vo.activity.ManjianzengzheGoodsQueryResultVO;
import com.yuanfeng.commoms.vo.activity.ManjianzengzhePromotionContentQueryResultVO;
import com.yuanfeng.commoms.vo.activity.ModularGoodsVO;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * @ClassName ActivityReductionPolicyBaseServiceImpl
 * @Description 满减赠折基本信息表
 * @Author cyp
 * @Date 2023-05-25 14:41:46
 * @Version 1.0
 **/
@Service
public class ActivityReductionPolicyBaseServiceImpl extends ServiceImpl<ActivityReductionPolicyBaseMapper, ActivityReductionPolicyBaseEntity>
        implements ActivityReductionPolicyBaseService {
    @Override
    public ManjianzengzheGoodsQueryResultVO selectByGoodsId(Integer commonId) {
        return this.baseMapper.selectByGoodsId(commonId);
    }

    @Override
    public List<ManjianzengzheGoodsRuleQueryDTO> selectList(Integer promotionId) {
        return this.baseMapper.selectList(promotionId);
    }

    @Override
    public List<ManjianzengzhePromotionContentQueryResultVO> selectContent(Integer commonId) {
        return this.baseMapper.selectContent(commonId);
    }

    @Override
    public ResponseResult selectAll(ListPageQueryParamDTO param) {
        try {
            //分页
            //将对象转换为map
            Map data = ParseMapUtils.beanToMap(param);
            //分页查询数据
            IPage<Map<String,Object>> page = this.baseMapper.webQueryActivityMapper(new Query<Map<String,Object>>().getPage(data),param);

            return ResponseResult.success(PageUtils.getPage(page));
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
        return ResponseResult.fail(BizCodeEnume.SYSTEM_ERROR.getCode(),BizCodeEnume.SYSTEM_ERROR.getMsg());
    }

    @Override
    public ResponseResult selectPrice(Integer goodsId) {
        ModularGoodsVO modularGoodsVO = this.baseMapper.selectPrice(goodsId);
        return ResponseResult.success(modularGoodsVO);
    }
}

